<?php
declare(strict_types=1);
namespace App\Api;

use App\ApiController;

use Field\SysMenuConst;
use Field\SysRoleAuthConst;
use Field\SysRoleConst;


// hook api_menu_use.php

/**
 * @title   用户
 * @auth    true
 * @rank    3
 */
class User extends ApiController
{
    // hook api_menu_start.php

    /**
     * @title  是否登录
     * @rank    99
     */
    public function action_IsLogin(): void
    {
        $flag = $this->request->cookie('flag');
        if(empty($flag)){
            $flag = md5($this->request->get_client_ip().time());
            $this->set_cookie('flag', $flag);
        }
        $data = $this->token->UserID ? $this->token->toArray():[];
        $data['flag']=$flag;
        $data['ip']=$this->request->get_client_ip();
        $this->response('0000',[
            'result' => $this->token->UserID ? 1 : 0,
            'timestrap'=>time(),
            'user' => $data
        ]);
    }

     /**
     * @title  会员信息
     * @login true
     * @rank    99
     */
    public function action_Info(): void
    {
        $data = $this->token->toArray();
        $data['Avatar'] = $this->upload_domain .($data['AvatarAt']? '/'.$data['UnID'].'.png':'/logo.png') ;
        unset($data['PassWord'], $data['Salt'], $data['UserID'], $data['ParentUserID']);

        $this->response('0000',['data' => $data]);
    }

    // hook api_menu_end.php

}

?>